<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition template="/template/DefaultTemplate.xhtml">
        <ui:define name="content">
            <h:panelGroup id="messagePanel" layout="block">
                <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
            </h:panelGroup>
            <h:form prependId="false" id="form"  >
                <p:panel header="List of purchase order having invoices need to be settled:" style="text-align: center">
                    <p:outputPanel id="books">  
                        <p:dataTable  value="#{vendorInvoiceEntityController.rpos}" var="rmq" widgetVar="userTable"
                                      paginator="true" rows="10"  
                                      paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"

                                      >


                            <p:column sortBy="#{rmq.rmq.vendor.companyName}" filterBy="#{rmq.rmq.vendor.companyName}">    <f:facet name="header">  
                                    <h:outputText value="Vendor Name" /> </f:facet>
                                <h:outputText value="#{rmq.rmq.vendor.companyName}" /> </p:column>

                            <p:column sortBy="#{rmq.rmq.rawMaterial.productName}" filterBy="#{rmq.rmq.rawMaterial.productName}">    <f:facet name="header">  
                                    <h:outputText value="Raw Material:" /> </f:facet>
                                <h:outputText value="#{rmq.rmq.rawMaterial.productName}" /> </p:column>


                            <p:column sortBy="#{rmq.quantity}" filterBy="#{rmq.quantity}">    <f:facet name="header">  
                                    <h:outputText value="Amount:" /> </f:facet>
                                <h:outputText value="#{rmq.quantity}" /> </p:column> 
                            <p:column sortBy="#{rmq.cost}" filterBy="#{rmq.cost}">    <f:facet name="header">  
                                    <h:outputText value="Cost:" /> </f:facet>
                                <h:outputText value="#{rmq.cost}" /> </p:column> 
                            <p:column>    <f:facet name="header">  
                                    <h:outputText value="Date Purchased:" /> </f:facet>
                                <h:outputText value="#{rmq.createdAt}" > 
                                    <f:convertDateTime pattern="dd/MM/yyyy" />
                                </h:outputText>
                            </p:column>
                            <p:column>    <f:facet name="header">  
                                    <h:outputText value="Having Invoices About To Due" /> </f:facet>
                                <h:outputText value="Yes!" rendered ="#{rmq.due}" /> 
                                <h:outputText value="Not Yet" rendered ="#{!rmq.due}" />
                            </p:column>


                            <p:column> 
                                <f:facet name="header">
                                    <h:outputText value="&nbsp;"/>
                                </f:facet>
                                <p:commandButton image="ui-icon ui-icon-search" value="View" update="table" oncomplete="carDialog.show()">
                                    <f:setPropertyActionListener value="#{rmq}"  
                                                                 target="#{vendorInvoiceEntityController.rpoSelect}" /> 
                                </p:commandButton>
                            </p:column>

                        </p:dataTable> 
                    </p:outputPanel>
                </p:panel>
                <p:separator/>
                <p:panel header="List of past invoices :" style="text-align: center">
                    <p:outputPanel id="bo1"> 

                        <p:dataTable id="table3"  value="#{vendorInvoiceEntityController.pastInvoice}" var="inv" 
                                     paginator="true" rows="10"  
                                     >
    <p:column sortBy="#{inv.externalId}" filterBy="#{inv.externalId}">    <f:facet name="header">  
                                    <h:outputText value="External Id:" /> </f:facet>
                                <h:outputText value="#{inv.externalId}" /> </p:column>


                            <p:column sortBy="#{inv.rawMaterialPurchaseOrder.rmq.vendor.companyName}" filterBy="#{inv.rawMaterialPurchaseOrder.rmq.vendor.companyName}">    <f:facet name="header">  
                                    <h:outputText value="Vendor Name" /> </f:facet>
                                <h:outputText value="#{inv.rawMaterialPurchaseOrder.rmq.vendor.companyName}" /> </p:column>

                            <p:column sortBy="#{inv.rawMaterialPurchaseOrder.rmq.rawMaterial.productName}" filterBy="#{inv.rawMaterialPurchaseOrder.rmq.rawMaterial.productName}">    <f:facet name="header">  
                                    <h:outputText value="Raw Material:" /> </f:facet>
                                <h:outputText value="#{inv.rawMaterialPurchaseOrder.rmq.rawMaterial.productName}" /> </p:column>


                            <p:column sortBy="#{inv.amount}" filterBy="#{inv.amount}">    <f:facet name="header">  
                                    <h:outputText value="Amount:" /> </f:facet>
                                <h:outputText value="#{inv.amount}" /> </p:column> 


                            <p:column>    <f:facet name="header">  
                                    <h:outputText value="Date Received:" /> </f:facet>
                                <h:outputText value="#{inv.dateReceived}" > 
                                    <f:convertDateTime pattern="dd/MM/yyyy" />
                                </h:outputText>
                            </p:column>

                            <p:column style="width:32px">  
                                <p:commandButton value ="More Info" ajax="false"
                                                 image="ui-icon ui-icon-search"  
                                                 action ="ViewPastInvoice?faces-redirect=true"
                                                 >
                                    <f:setPropertyActionListener value="#{inv}"  
                                                                 target="#{vendorInvoiceEntityController.selectedInvoice}"/>  
                                </p:commandButton>  
                            </p:column> 

                        </p:dataTable> 
                    </p:outputPanel>
                </p:panel>
                <br/>
             

                <p:dialog header="Invoice for this order:" widgetVar="carDialog" resizable="false"  
                          width="900" height="250" modal="true" showEffect="explode" hideEffect="explode">  

                    <h:form prependId="false">
                        <p:dataTable id="table"  value="#{vendorInvoiceEntityController.invoiceList}" var="inv" 
                                     paginator="true" rows="10"  
                                     >



                            <p:column sortBy="#{inv.rawMaterialPurchaseOrder.rmq.vendor.companyName}" filterBy="#{inv.rawMaterialPurchaseOrder.rmq.vendor.companyName}">    <f:facet name="header">  
                                    <h:outputText value="Vendor Name" /> </f:facet>
                                <h:outputText value="#{inv.rawMaterialPurchaseOrder.rmq.vendor.companyName}" /> </p:column>

                            <p:column sortBy="#{inv.rawMaterialPurchaseOrder.rmq.rawMaterial.productName}" filterBy="#{inv.rawMaterialPurchaseOrder.rmq.rawMaterial.productName}">    <f:facet name="header">  
                                    <h:outputText value="Raw Material:" /> </f:facet>
                                <h:outputText value="#{inv.rawMaterialPurchaseOrder.rmq.rawMaterial.productName}" /> </p:column>


                            <p:column sortBy="#{inv.amount}" filterBy="#{inv.amount}">    <f:facet name="header">  
                                    <h:outputText value="Amount:" /> </f:facet>
                                <h:outputText value="#{inv.amount}" /> </p:column> 
                            <p:column>    <f:facet name="header">  
                                    <h:outputText value="Due Date:" /> </f:facet>
                                <h:outputText value="#{inv.dueDate}" > 
                                    <f:convertDateTime pattern="dd/MM/yyyy" />
                                </h:outputText>
                            </p:column>

                            <p:column>    <f:facet name="header">  
                                    <h:outputText value="Date Received:" /> </f:facet>
                                <h:outputText value="#{inv.dateReceived}" > 
                                    <f:convertDateTime pattern="dd/MM/yyyy" />
                                </h:outputText>
                            </p:column>
                            <p:column sortBy="#{inv.status}" filterBy="#{inv.status}">    <f:facet name="header">  
                                    <h:outputText value="Status" /> </f:facet>
                                <h:outputText value="#{inv.status}" /> </p:column>
                            <p:column style="width:32px">  
                                <p:commandButton value ="View Invoice Detail" ajax="false"
                                                 image="ui-icon ui-icon-search"  
                                                 action ="OrderInvoiceDetail?faces-redirect=true"
                                                 >
                                    <f:setPropertyActionListener value="#{inv}"  
                                                                 target="#{vendorInvoiceEntityController.selectedInvoice}"/>  
                                </p:commandButton>  
                            </p:column> 
                        </p:dataTable> 
                    </h:form>
                </p:dialog>  

                <br/>

            </h:form>
        </ui:define>
    </ui:composition>

</html>